package com.briup.estore.web.controller;

import com.briup.estore.service.ShopCarService;
import com.briup.estore.vo.ShopCarVO;
import com.briup.estore.web.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@Api(tags = "购物车")
@RequestMapping("/shopCar")
public class ShopCarController {
    @Autowired
    private ShopCarService shopcarService;

    @PutMapping("/{id}")
    @ApiOperation("书籍添加购物车")
    public Result addShopCar(@PathVariable("id") Integer bookId, HttpServletRequest request) {
        String userId = (String) request.getAttribute("userId");
        shopcarService.add(Integer.parseInt(userId), bookId);
        return Result.success();
    }
    @GetMapping("/")
    @ApiOperation("查询当前用户的购物车列表")
    public Result getShopCars(HttpServletRequest request) {
        String userId = (String) request.getAttribute("userId");
        List<ShopCarVO> voList =
                shopcarService.findLists(Integer.parseInt(userId));
        return Result.success(voList);
    }

    @DeleteMapping("/")
    @ApiOperation("删除购物车")
    public void deleteshopCar(List<Integer> shopCarlist) {
        shopcarService.deleteshopCar(shopCarlist);
//        return Result.success();
    }
}